<?php
/**
 * View Nuovo Post - LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    21-apr-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/js/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript" src="/js/ckeditor/load-editor.js"></script>
<script type="text/javascript">
    //<![CDATA[
    
    $(document).ready(function() {
        $("#post_title").rules("add", {
            required: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $("#post_text").rules("add", {
            required: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $(".radio").rules("add", {
            required: true,
            messages: {
                required: "<?php echo sprintf( ERR_EMPTY_SELECT, 'Categoria' ) ?>"
            }
        });
        
        validator.groups = {day: "dateValid", month: "dateValid", year: "dateValid"}

	// Datepicker
	$( "#year" ).datepicker({
	    // Riempie i campi della data...
	    onSelect: function(dateText, inst) {
		var theDate = new Date(Date.parse($(this).datepicker('getDate')));
		var day = $.datepicker.formatDate('dd', theDate);
		var month = $.datepicker.formatDate('mm', theDate);
		var year = $.datepicker.formatDate('yy', theDate);
		$('#day').val(day);
		$('#month').val(month);
		$('#year').val(year);
	    },
	    showOn: "button",
	    showAnim: 'blind',
	    buttonImage: "/images/admin/calendar.png",
	    buttonImageOnly: true
	});
        
	$( '#post_text' ).ckeditor(function(){}, ckeditorConf );
 
        $("#salva").click(function() {
            // Risolve un bug d'integrazione tra jQuery e CKeditor
            CKEDITOR.instances.post_text.updateElement();

            return validator.element( "#post_text" );
        });

    });

    //]]>
</script>

<div class="info">
    <h2>Inserisci Nuovo Post</h2>
    <div>Per inserire un nuovo post...</div>
    <div>I campi contrassegnati da <span class="req">*</span> sono obbligatori!</div>
</div>
<!-- This <div> holds alert messages to be display in the sample page. -->
<div id="alerts">
    <noscript>
    <p>
	<strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
				support, like yours, you should still see the contents (HTML data) and you should
				be able to edit it normally, without a rich editor interface.
    </p>
    </noscript>
</div>
<form class="fab" name="postForm" id="postForm" action="/admin/posts/info/id/<?php echo $this->post_id ?>" method="post" enctype="multipart/form-data">

    <ul>
    <li class="paging-context ">
        <table class="pgStyle1 circle2" cellspacing="0">
            <tr>
                <td class="c selected">
                    <var>1</var>
                </td>
                <td class="t selected">
                    <b id="pagecircle1">Post</b>
                </td>
                <td class="c ">
                    <var>2</var>
                </td>
                <td class="t">
                    <b id="pagecircle2">Immagine</b>
                </td>
                <td class="c">
                    <var>3</var>
                </td>
                <td class="t">
                    <b id="pagecircle2">Anteprima</b>
                </td>                
            </tr>
        </table>
    </li>
    </ul>
<div id="content">
    <ul>
        <li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none' ?>">
            <h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
            <p id="errorMsg">
            Di seguito trovi evidenziati gli errori riscontrati.
            </p>
        </li>

        <li class="<?php echo $this->errorMsg['post_title'] ? 'error' : '' ?>">
            <label class="desc <?php echo $this->errorMsg['post_title'] ? 'error' : '' ?>">Titolo<span class="req">*</span></label>
            <div>
                <span>
                    <input id="post_title" name="post_title" class="field text large" type="text" maxlength="255" value="<?php echo $this->data['post_title'] ?>" /> 
                </span>
            </div>
            <p class="error" style="<?php echo $this->errorMsg['post_title'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['post_title'] ?></p>
        </li>

        <li class="<?php echo $this->errorMsg['post_text'] ? 'error' : '' ?>">
            <label class="desc <?php echo $this->errorMsg['post_text'] ? 'error' : '' ?>">Testo<span class="req">*</span></label>
            <div>
                <span>
                    <textarea id="post_text" name="post_text" rows="10" cols="50"><?php echo htmlentities( $this->data['post_text'] ) ?></textarea>
                </span>
            </div>
            <p class="error" style="<?php echo $this->errorMsg['post_text'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['post_text'] ?></p>
        </li>

        <li class="section">
            <h3>Altre Informazioni</h3>
        </li>

        <li class="<?php echo $this->errorMsg['post_published'] ? 'error' : '' ?>">
            <label class="desc <?php echo $this->errorMsg['post_published'] ? 'error' : '' ?>">Data</label>
            <div class="float-left">
                <span class="input">
                    <input class="field text dateValid" name="day" id="day" size="2" type="text" maxlength="2" value="<?php echo $this->data['post_published_d'] ? $this->data['post_published_d'] : date( 'd' ) ?>" /> / 
                    <label>DD</label>
                </span>

                <span class="input">
                    <input class="field text dateValid" name="month" id="month" size="2" type="text" maxlength="2" value="<?php echo $this->data['post_published_m'] ? $this->data['post_published_m'] : date( 'm' ) ?>" /> / 
                    <label>MM</label>
                </span>

                <span class="input">
                    <input class="field text dateValid" name="year" id="year" size="4" type="text" maxlength="4" value="<?php echo $this->data['post_published_y'] ? $this->data['post_published_y'] : date( 'Y' ) ?>" />
                    <label>YYYY</label>
                </span>

<!--		<span class="input">
<img alt="Pick a date." src="/images/admin/calendar.png" onclick="$('#datepicker').trigger('click');" class="datepicker" id="datepicker">
            </span>-->
            </div>
            <p class="error" style="<?php echo $this->errorMsg['post_published'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['post_published'] ?></p>
            <p id="instruct2" class="instruct">
                <small>Inserisci la data di pubblicazione del post.
                    <br/>Questo verr&agrave; visualizzato online a partire dalla data inserita.</small>
            </p>
        </li>

        <li class="<?php echo $this->errorMsg['post_category'] ? 'error' : '' ?>">
            <label class="desc <?php echo $this->errorMsg['post_category'] ? 'error' : '' ?>">Categoria</label>
            <div>
                <?php foreach( $this->categories as $category ) : ?>
                <span class="input">
                    <input id="<?php echo $category['category_name'] ?>" name="post_category[]" class="field radio" type="checkbox" value="<?php echo $category['category_id'] ?>" <?php echo ( is_array( $this->data['post_categories'] ) AND array_key_exists( $category['category_id'], $this->data['post_categories'] ) ) ? 'checked="checked"' : '' ?> />
                    <label class="choice" for="<?php echo $category['category_name'] ?>"><?php echo $category['category_name'] ?></label>
                </span>
                <?php endforeach; ?>
            </div>
            <p class="error" style="<?php echo $this->errorMsg['post_category'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['post_category'] ?></p>
        </li>

        <li class="<?php echo $this->errorMsg['post_tags'] ? 'error' : '' ?>">
            <label class="desc <?php echo $this->errorMsg['post_tags'] ? 'error' : '' ?>">Tags</label>
            <div>
                <span>
                    <input id="post_tags" name="post_tags" class="field text large" type="text" maxlength="255" value="<?php echo $this->data['post_tags'] ?>" /> 
                </span>
            </div>
            <p class="error" style="<?php echo $this->errorMsg['post_tags'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['post_tags'] ?></p>
            <p id="instruct1" class="instruct">
                <small>Inserisci i tag separati da <strong>;</strong>.
                    <br/>Es: <strong>tag1</strong>; <strong>tag2</strong>;</small>
            </p>
        </li>
        <li>
            &nbsp;
        </li>
    </ul>
</div>
    <div id="formButtons">
        <button id="salva" type="submit" name="salva" value="salva" class="button positive">
            <img src="/images/admin/tick.png" alt="" />Continua
        </button>
        <button id="annulla" name="annulla" value="annulla" class="button negative">
            <img src="/images/admin/cross.png" alt="" />Annulla
        </button>
    </div>
</form>
